<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Page_model extends MY_Model
{

    public function __construct() {
        parent::__construct();
    }

    public function getAll()
    {
        return $this->db->get('pages')
                ->result();
    }

    public function get($id)
    {
        return $this->db->where('id', $id)
                ->get('pages')
                ->row();
    }

    public function getBySlug($slug, $lang)
    {
        return $this->db->where('slug', $slug)
                ->where('lang', $lang)
                ->get('pages')
                ->row();
    }

    public function update($id, $data)
    {
        return $this->db->where('id', $id)
                ->set($data)
                ->update('pages');
    }

    public function getCategoryPageList($ctg_slug, $lang)
    {
        $ctg = $this->db->where('slug', $ctg_slug)
                ->where('lang', $lang)
                ->get('categories')
                ->row();

        return $this->db->where('category', $ctg->id)
                ->get('pages')
                ->result();
    }

    public function getCategorySlug($id)
    {
        $row = $this->db->where('id', $id)
                ->get('categories')
                ->row();

        return $row->slug;
    }

    public function ctg_slug_exists($slug, $lang)
    {
        $count = $this->db->where('slug', $slug)
                    ->where('lang', $lang)
                    ->from('categories')
                    ->count_all_results();

        return $count > 0;
    }

    public function page_slug_exists($slug, $lang)
    {
        $count = $this->db->where('slug', $slug)
                    ->where('lang', $lang)
                    ->from('pages')
                    ->count_all_results();

        return $count > 0;
    }

}

/* End of file page_model.php */
/* Location: ./application/page_model.php */